package cn.chinaunicom.sdsi.gacx.contractMng.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;

import cn.chinaunicom.sdsi.frm.base.BaseService;
import cn.chinaunicom.sdsi.gacx.contractMng.dao.mybatis.TravelContractModelMapper;
import cn.chinaunicom.sdsi.gacx.contractMng.entity.TravelContractModelEntity;
import cn.chinaunicom.sdsi.gacx.contractMng.service.ContractMngService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service
public class ContractMngServiceImpl extends BaseService implements ContractMngService {
	
	@Autowired
	private TravelContractModelMapper travelContractModelMapper;
	
	@Override
	public JSONObject qryTrlContMdlList(String contractName, Integer start, Integer length){
		setPageInfo(start, length);
		List<TravelContractModelEntity> result = travelContractModelMapper.qryTrlContMdlList(contractName);
		PageInfo<TravelContractModelEntity> page = new PageInfo<TravelContractModelEntity>(result);
		JSONArray array = JSONArray.fromObject(result);
		JSONObject obj = new JSONObject();
		obj.element("data", array);
		obj.element("recordsTotal", page.getTotal());
		obj.element("recordsFiltered", page.getTotal());
		obj.element("draw", 0);
		return obj;
	}
	
	@Override
	public void saveContractTmp(TravelContractModelEntity tcme){
		travelContractModelMapper.saveContractTmp(tcme);
	}
	
	@Override
	public int delTrlContMdlById(String contractId){
		return travelContractModelMapper.delTrlContMdlById(contractId);
	}
	
	@Override
	public int qryTrlContMdlByName(String contractName){
		return travelContractModelMapper.qryTrlContMdlByName(contractName);
	}
	
	@Override
	public TravelContractModelEntity qryTrvlTmpMdlById(String contractId){
		return travelContractModelMapper.qryTrvlTmpMdlById(contractId);
	}
}
